
import util from "../../common/js/util.js";
var app = getApp();
import Qs from "qs";


// {
//   ADD_TIME: "2022-04-26 15:40:45"
//   ENCLOSURE_ID: "e7ef60a960544be181e6fe748b88c12f"
//   FILE_NAME: "www"
//   FILE_TYPE: ".png"
//   PATH: "uploadFiles/uploadImgs/20220426/57ff564c40c347f9bc4993955a27185a.png"
//   STATUS: 1
//   TYPE_NAME: "logistics"
//   icon: "http://test.yuehong.pro/YhERP/uploadFiles/uploadImgs/20220426/57ff564c40c347f9bc4993955a27185a.png"
//   name: "www"
//   url: "http://test.yuehong.pro/YhERP/uploadFiles/uploadImgs/20220426/57ff564c40c347f9bc4993955a27185a.png"
// }


Component({
  mixins: [],
  data: {
    file_list: [],
    url: "",
    show: false
  },
  props: {
    file_list: [],
  },
  didMount() {

    if (util.isNotEmpty(this.props.file_list)) {
      this.setData({
        file_list: this.props.file_list
      })

    }
  },
  didUpdate() {
    if (util.isNotEmpty(this.props.file_list)) {
      // console.log("---file_list:",this.props.file_list);
      this.setData({
        file_list: this.props.file_list
      })

    }
  },
  didUnmount() { },
  methods: {
    initData(list) {
      this.props.file_list = list;
      for (let index = 0; index < list.length; index++) {
        const element = list[index];
        if(element.url){
          element.url=util.urlHttpToHttps(element.url);
        }
        switch (element.FILE_TYPE) {
          
          case ".pdf":
            element.icon = "/static/img/office-pdf.png";
            element.is_web_view = 1;
            break;
          case ".doc":
          case ".docx":
            element.icon = "/static/img/office-word.png";
            element.is_web_view = 1;
            break;
          case ".xls":
          case ".xlsx":
            element.icon = "/static/img/office-excel.png";
            element.is_web_view = 1;
            break;
          default:
            element.icon = element.url;
            break;
        }
      }
      this.setData({
        file_list: list
      })
     // console.log(list);

    },
    imgClick(e) {
      let url = e.currentTarget.dataset.url;
      let index = e.currentTarget.dataset.index;
      let data = this.data.file_list[index];
      let FILE_TYPE = data.FILE_TYPE;
      this.setData({
        url
      });
      // png jpeg png
      if (FILE_TYPE.indexOf("g") != -1) {
        this.previewImage(url);
      } else {
        this.otherPreview(data);
      }
    },
    otherPreview(data) {
      let json={
        PATH:data.url?data.url:data.PATH,
        FILE_TYPE:data.FILE_TYPE,
        patch : "/pages/radio/radio/radio",
        icon:data.icon
      }
      let p = Qs.stringify(json);
   //  console.log("--查看合同",json);
      let path = '/pages/web_view/file_view/file_view';
      // console.log(p);
      let to_url = `${path}?${p}`;
      dd.navigateTo({
        url: to_url
      })
    },
    previewImage(url) {
      dd.previewImage({
        current: 1,
        urls: [
          url
        ],
      });
    },
    onMaskClick() {
      this.setData({
        show: false,
      });
    },
  },
});
